package com.fxbin123.config;

import com.alibaba.fastjson.JSON;
import com.fxbin123.bean.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * @author: fxbin
 * @datetime: 2018/6/21 17:43
 * @description:
 */
@Slf4j
@Component
public class KafkaSender {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    /**
     * 发送消息的方法
     */
    public void send() {
        Message message = new Message();
        message.setId(System.currentTimeMillis());
        message.setMsg(UUID.randomUUID().toString());
        message.setSendTime(LocalDateTime.now());
        log.info("+++++++++++++++++++++  message = {}", JSON.toJSON(message));
        kafkaTemplate.send("Y.S.K", JSON.toJSON(message).toString());

    }





}
